We can use the base plot functions in R to create a plot of the pmf for a Poisson random variable \(X\) with \(\lambda = 4.8\) — i.e. \(X\ \tilde \ \mbox{Pois}(4.8)\).
lambda <- 4.8
x <- -1:14
pmf <- dpois(x, lambda)
plot(x, pmf, type="h", xlab="x", ylab="p = P(X=x)", main="X~Pois(4.8)", ylim=c(0, 0.25), xaxt="n")
axis(1,at=seq(0,14,by=2))
text(x, pmf+0.005, round(pmf, digits=4), cex=0.6)
abline(v=lambda, col="blue")
The CDF may be plotted analogously.
x <- -1:15
cdf <- ppois(x, lambda)
plot(x, cdf, type="s", xlab="x", ylab="P(X<=c)", main="X~Pois(4.8)", xaxt="n")
axis(1, at=seq(0,14,by=2))
abline(h=0.5, col="yellow")
abline(v=qpois(0.5,lambda), col="yellow")
Just for fun we can overlay the two.
pmf <- dpois(x, lambda)
plot(x, pmf, type="h", xlab="x", ylab="p", main="X~Pois(4.8)", ylim=c(0, 1), xaxt="n", col="red", lty=3)
lines(x, cdf, type="s", xlab="x", ylab="P(X<=c)", main="X~Pois(4.8)", xaxt="n")
axis(1,at=seq(0,14,by=2))
Now look for the median.
data.frame(x,pmf,cdf,invcdf=1-cdf)
## x pmf cdf invcdf
## 1 -1 0.0000000000 0.000000000 1.000000e+00
## 2 0 0.0082297470 0.008229747 9.917703e-01
## 3 1 0.0395027858 0.047732533 9.522675e-01
## 4 2 0.0948066860 0.142539219 8.574608e-01
## 5 3 0.1516906976 0.294229916 7.057701e-01
## 6 4 0.1820288371 0.476258754 5.237412e-01
## 7 5 0.1747476836 0.651006437 3.489936e-01
## 8 6 0.1397981469 0.790804584 2.091954e-01
## 9 7 0.0958615865 0.886666171 1.133338e-01
## 10 8 0.0575169519 0.944183123 5.581688e-02
## 11 9 0.0306757077 0.974858830 2.514117e-02
## 12 10 0.0147243397 0.989583170 1.041683e-02
## 13 11 0.0064251664 0.996008336 3.991664e-03
## 14 12 0.0025700666 0.998578403 1.421597e-03
## 15 13 0.0009489477 0.999527350 4.726495e-04
## 16 14 0.0003253535 0.999852704 1.472960e-04
## 17 15 0.0001041131 0.999956817 4.318292e-05
plot(x,cdf,type="s", xlab="x", ylab="P(X<=c)", main="X~B(13, 0.6)", xaxt="n")
lines(x,1-cdf,type="s", xlab="x", xaxt="n")
axis(1,at=seq(0,14,by=2))
abline(h=0.5, col="red", lty=2)
We now look at how well the Poisson approximates the binomial.
n <- 100
p <- 0.01
x <- 0:3
pois.pmf <- dpois(x, n*p)
pois.cdf <- ppois(x, n*p)
binom.pmf <- dbinom(x, n, p)
binom.cdf <- pbinom(x, n, p)
data.frame(pois.pmf, pois.cdf, binom.pmf, binom.cdf)
## pois.pmf pois.cdf binom.pmf binom.cdf
## 1 0.36787944 0.3678794 0.36603234 0.3660323
## 2 0.36787944 0.7357589 0.36972964 0.7357620
## 3 0.18393972 0.9196986 0.18486482 0.9206268
## 4 0.06131324 0.9810118 0.06099917 0.9816260
We let R plot the values that we computed in class.
x <- 0:25
pmf.24 <- dpois(x, 2.4)
pmf.48 <- dpois(x, 4.8)
pmf.96 <- dpois(x, 9.6)
plot(x, pmf.24, pch=1, col=1, xlab="x", ylab="p")
points(x, pmf.48, pch=2, col=2)
points(x, pmf.96, pch=3, col=3)
abline(v = c(2.4, 4.8, 9.6), col=1:3, lty=2)